package com.dao.impl;

import com.dao.TeacherDao;
import com.entity.Teacher;
import com.entity.TeacherExample;
import com.mapper.TeacherMapper;
import com.page.PageInfo;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("teacherDao")
public class TeacherDaoImpl implements TeacherDao {
    @Resource
    public TeacherMapper teacherMapper;
    @Override
//    public List<Teacher> getTeacherByPage(PageInfo pageInfo) {
//        TeacherExample teacherExample = new TeacherExample();
//        teacherExample.setOffset(pageInfo.getOffset());
//        teacherExample.setLimit(pageInfo.getPageSize());
//        return teacherMapper.selectByExample(teacherExample);
//    }

    public List<Teacher> getTeacherByPage(PageInfo pageInfo)  throws Exception{
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        int itemCount = (int)teacherMapper.countByExample(null);
        pageInfo.setItemCount(itemCount);
        return teacherMapper.getTeachersByPage(map);
    }

    public Teacher selectByTnoWithScs(String tno) throws Exception{

        return teacherMapper.selectByTnoWithScs(tno);
    }

    public Integer addTeacher(Teacher teacher)  throws Exception{

        return teacherMapper.insertSelective(teacher);
    }
    public Integer editTeacher(Teacher teacher)  throws Exception{

        return teacherMapper.updateByPrimaryKeySelective(teacher);
    }


    public String getMaxId(){
        return teacherMapper.getMaxId();
    }
}
